//
//  CategoryViewController.m
//  BigJoy
//
//  Created by Rowling on 2017/6/14.
//  Copyright © 2017年 Rowling. All rights reserved.
//

#import "CategoryViewController.h"
#import "XMIndexHeaderView.h"
#import "CategoryListViewController.h"
#import "XMSearchViewController.h"
#import "CategoryIndexView.h"
#import "choseTakePhotoVIew.h"

@interface CategoryViewController ()

@end

@implementation CategoryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = defaultBackColor;
    [self setUpUI];
}

-(void)setUpUI {
    [self cutomNavBarView];
    @weakify(self);
    [[self.serchView.searchbutton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        XMSearchViewController * vc = [[XMSearchViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }];
    [self.serchView.leftButton setImage:[UIImage imageNamed:@"refresh_arrow"] forState:UIControlStateNormal];
    [self.serchView.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@30);
    }];
    [self.serchView.leftButton layoutIfNeeded];
    [[self.serchView.leftButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        [self.navigationController popViewControllerAnimated:YES];
    }];
    
    CategoryIndexView * indexView = [CategoryIndexView fastLogin];
    indexView.frame = CGRectMake(0, 64, SCREEN_WIDTH, 50);
    // indexView点击事件
    [indexView setClickBlock:^(UIButton * btn){
//        @strongify(self);
        if (btn.tag == 103) {
            // 价格点击
            choseTakePhotoVIew * choseView = [[choseTakePhotoVIew alloc]initHeadWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) viewY:115 titleArray:@[@"价格由低到高",@"价格由高到低"]];
//            @weakify(self);
            [choseView.subject subscribeNext:^(id  _Nullable x) {
//                @strongify(self);
                NSInteger index = [x integerValue];
                NSLog(@"%ld",index);
            }];
            choseView.font = [UIFont systemFontOfSize:13];
            choseView.fontColor = [UIColor colorForHex:@"666666"];
            [XMKEYWINDOWXM addSubview:choseView];
        }
    }];
    [self.view addSubview:indexView];
    CategoryListViewController * listVC = [[CategoryListViewController alloc]init];
    [self addChildViewController:listVC];
    listVC.view.frame = CGRectMake(0, CGRectGetMaxY(indexView.frame), SCREEN_WIDTH, self.view.height - 50);
    [self.view addSubview:listVC.view];
    [listVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(indexView.mas_bottom);
        make.right.left.bottom.equalTo(self.view);
    }];
}


@end
